#!/usr/bin/python
# -*- coding: utf-8 -*-

class MathSelf():
    
    def difineNodeid(self):
        res = '0x%x'% random.randint(99, 9999999)
        self.mayaPrint( res )
        return res
        
    def averageNumber(self,evStep,counts,_range=[0.0,1.0]):
        """averageNumber: funtiont in OF3D_PublicClass/mathSelf.py/
        can average value from a value to b value
        evStep: control increment or decreasing
        counts: many spans
        _rang:from to
        """
        #wrong number input raise
        if evStep>1.0 or evStep<0.0:
            raise TypeError( " evStep must in range 0.0~1.0 " )
        if len(_range)!=2 or _range[0]>_range[1]:
            raise TypeError( "Range must input 2 value list and value1<=value2 " )
            
        resStep = [0.0]
        #
        if evStep==1:
            for i in range(counts):
                resStep.append( 1.0 )
        elif evStep!=0:
            tempStList = []
            dev = 0.0
            flMax = 1.0
            for i in range(counts):
                flMax = flMax-flMax*evStep
                dev += flMax*evStep
                tempStList.append( dev )
            for v in tempStList:
                resStep.append( v/dev )
        else:
            v = 0.0
            devNum = 1.0/counts
            for i in range(counts):
                v += devNum
                resStep.append( v )
        #remapValue
        if _range!=[0.0,1.0]:
            resStep = self.remapValue(resStep,[0.0,1.0],_range)
        return resStep
        
    def remapValue(self,inputValue,inputRange,outputRange):
        """Remap Value: that allows you to take an input value list and remap its value list with liner.
        One can remap this to a new output scalar value.
        """
        if type(inputValue)==list:
            res = []
            for val in inputValue:
                location = float(val)/(inputRange[1]-inputRange[0])
                resVal = outputRange[0]+(outputRange[1]-outputRange[0])*location
                res.append( resVal )
            return res
        else:
            location = float(inputValue)/(inputRange[1]-inputRange[0])
            resVal = outputRange[0]+(outputRange[1]-outputRange[0])*location
            return resVal
            
    def zchABDistance(self,posA,posB):
        """sqrt((pow((a[0]-b[0]),2)+pow((a[1]-b[1]) ,2)+pow((a[2]-b[2]) ,2)))"""
        zchABdistance = None
        zchABdistance = float(pow((pow((posA[0]-posB[0]),2)+pow((posA[1]-posB[1]) ,2)+pow((posA[2]-posB[2]) ,2)),0.5))
        return zchABdistance
        
    def usingTime(self,tm):
        Hour,Min,Sec = tm/3600,tm/60%60,tm%60
        hour = str(Hour).zfill(2)
        min = str(Min).zfill(2)
        sec = str(Sec).zfill(2)
        return "%s:%s:%s"%(hour,min,sec)